package com.zhongyu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhongyu.mapper.OrderMapper;
import com.zhongyu.pojo.Order;
import com.zhongyu.service.OrderService;
import com.zhongyu.vo.OrderVo;
import com.zhongyu.vo.PageResult;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;

@Service("OrderService")
public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements OrderService {

@Resource
private OrderMapper orderMapper;
    @Override
    public List<Order> searchAll() {
        return orderMapper.findAll();
    }
    @Override
    public void update(String state, LocalDateTime purchaseTime, Integer id) {
        orderMapper.update(state,purchaseTime,id);

    }
    @Override
    public PageResult searchSal(Integer pageNo, Integer pageSize, OrderVo orderVo) {
/*        LambdaQueryWrapper<Order> queryWrapper= Wrappers.<Order>lambdaQuery();
        queryWrapper.eq(orderVo.getChecker()!=null,Order::getChecker,orderVo.getChecker())
                .eq(orderVo.getProvider()!=null,Order::getProvider,orderVo.getProvider())
                .eq(orderVo.getProviderId()!=null,Order::getProviderId,orderVo.getProviderId())
                .eq(orderVo.getState()!=null,Order::getState,orderVo.getStartDate())
                .eq(orderVo.getType()!=null,Order::getType,orderVo.getType());*/
        Page page=new Page(pageNo,pageSize);
        List<Order> list=orderMapper.searchSal(page);
        return new PageResult(list,page.getTotal());

    }
    @Override
    public PageResult searchAll(Integer pageNo, Integer pageSize, OrderVo orderVo) {
       /* LambdaQueryWrapper<Order> queryWrapper= Wrappers.<Order>lambdaQuery();
        queryWrapper.eq(orderVo.getChecker()!=null,Order::getChecker,orderVo.getChecker())
                .eq(orderVo.getProvider()!=null,Order::getProvider,orderVo.getProvider())
                .eq(orderVo.getProviderId()!=null,Order::getProviderId,orderVo.getProviderId())
                .eq(orderVo.getState()!=null,Order::getState,orderVo.getStartDate())
                .eq(orderVo.getType()!=null,Order::getType,orderVo.getType());*/
        Page page=new Page(pageNo,pageSize);
        List<Order> list=orderMapper.searchAll(page);
        return new PageResult(list,page.getTotal());

    }
}
